<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<link href="<c:url value="${assetsUrl}/css/viewing.css"/>" rel="stylesheet">
<div id="wrapper">
    <div>
        <span>${iStatus}</span>
    </div>
    <div class="main-viewing">
        <table border="1" cellspacing="0" cellpadding="0">
            <tbody>
                <tr>
                    <td>SÁNG</td>
                    <td>
                        <table class="class" border="1" cellspacing="0" cellpadding="0" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td rowspan="2 colEnd">Lớp</td>
                                    <% for (int i = 2; i <= 6; i += 1) {%>
                                    <td colspan="6" class="date colEnd">Thứ <%= i%></td>
                                    <% }%>
                                </tr>
                                <!-- Start Slot -->
                                <tr>
                                    <% for (int i = 2; i <= 6; i += 1) {%>
                                    <% for (int j = 1; j <= 6; j += 1) {%>
                                    <!-- slot 1 to 6 -->
                                    <td class="slot1 single"><%= j%></td>
                                    <% }%>
                                    <% }%>
                                </tr>
                                <!-- End Slot -->
                                <c:forEach var="aclass" items="${dataClasses}" >
                                    <!-- Start class -->
                                    <tr>
                                        <td>${aclass.name}</td>
                                        <c:forEach var="timetabling" items="${ListDateCombo}" >
                                            <c:if test="${aclass.code == timetabling.key}">
                                                <!-- Foreach by class code  -->
                                                <c:forEach var="timetable" items="${timetabling.value}" >
                                                    <c:choose>
                                                        <c:when test="${timetable.value.size() > 0}">
                                                            <c:set var="iCount" value="1"/>
                                                            <c:forEach var="i" begin="0" end="${timetable.value.size() - 1}" >
                                                                <c:choose>
                                                                    <c:when test="${timetable.value.get(i).slot == iCount}">
                                                                        <td colspan="${timetable.value.get(i).courses.credits}">
                                                                            ${timetable.value.get(i).courses.name} 
                                                                            (${timetable.value.get(i).rooms.name} : T ${timetable.value.get(i).slot} : D ${timetable.value.get(i).day})
                                                                        </td>
                                                                        <c:set var="iCount" value="${iCount + timetable.value.get(i).courses.credits}"/>
                                                                        <!-- For Type 2 -->
                                                                        <c:if test="${i == (timetable.value.size()-1)}">
                                                                            <c:if test="${iCount <= 6}">
                                                                            <c:forEach var="l" begin="${iCount}" end="6" >
                                                                                    <c:if test="${iCount <= 6}">
                                                                                        <td class="slot1 single empty"></td>
                                                                                        <c:set var="iCount" value="${iCount + 1}"/>
                                                                                    </c:if>
                                                                            </c:forEach>
                                                                            </c:if>
                                                                        </c:if>
                                                                    </c:when>
                                                                    <c:otherwise>
                                                                        <c:if test="${iCount < timetable.value.get(i).slot}">
                                                                            <c:forEach var="j" begin="${iCount}" end="${timetable.value.get(i).slot - 1}" >
                                                                                <c:if test="${iCount <= 6}">
                                                                                    <td class="slot1 single empty"></td>
                                                                                    <c:set var="iCount" value="${iCount + 1}"/>
                                                                                </c:if>
                                                                            </c:forEach>
                                                                        </c:if>
                                                                        <!-- For Type 1 -->
                                                                        <c:if test="${(iCount + timetable.value.get(i).courses.credits - 1) <= 6}">
                                                                            <td colspan="${timetable.value.get(i).courses.credits}">
                                                                                ${timetable.value.get(i).courses.name} 
                                                                                (${timetable.value.get(i).rooms.name} : T ${timetable.value.get(i).slot} : D ${timetable.value.get(i).day})
                                                                            </td>
                                                                            <c:set var="iCount" value="${iCount + timetable.value.get(i).courses.credits}"/>
                                                                        </c:if>
                                                                        <!-- For Type 3 -->    
                                                                        <c:if test="${i == (timetable.value.size()-1)}">
                                                                            <c:if test="${iCount <= 6}">
                                                                            <c:forEach var="l" begin="${iCount}" end="6" >
                                                                                    <c:if test="${iCount <= 6}">
                                                                                        <td class="slot1 single empty"></td>
                                                                                        <c:set var="iCount" value="${iCount + 1}"/>
                                                                                    </c:if>
                                                                            </c:forEach>
                                                                            </c:if>
                                                                        </c:if>    
                                                                    </c:otherwise>
                                                                </c:choose>
                                                            </c:forEach>    
                                                            
                                                        </c:when>
                                                        <c:otherwise>
                                                            <!-- Display a blank row if there no data  -->
                                                            <td colspan="6" class="slot1 single empty"></td>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </c:forEach>
                                                <!-- END Foreach by class code  -->
                                            </c:if>
                                        </c:forEach>
                                    </tr>
                                    <!-- End class -->
                                </c:forEach>
                            </tbody>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td>CHIỀU</td>
                    <td>
                        <table class="class" border="1" cellspacing="0" cellpadding="0" style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td rowspan="2 colEnd">Lớp</td>
                                    <% for (int i = 2; i <= 6; i += 1) {%>
                                    <td colspan="6" class="date colEnd">Thứ <%= i%></td>
                                    <% }%>
                                </tr>
                                <!-- Start Slot -->
                                <tr>
                                    <% for (int i = 2; i <= 6; i += 1) {%>
                                    <% for (int j = 1; j <= 6; j += 1) {%>
                                    <!-- slot 1 to 6 -->
                                    <td class="slot1 single"><%= j%></td>
                                    <% }%>
                                    <% }%>
                                </tr>
                                <!-- End Slot -->
                                <c:forEach var="aclass" items="${dataClasses}" >
                                    <!-- Start class -->
                                    <tr>
                                        <td>${aclass.name}</td>
                                        <c:forEach var="timetabling" items="${ListDateComboAfternoon}" >
                                            <c:if test="${aclass.code == timetabling.key}">
                                                <!-- Foreach by class code  -->
                                                <c:forEach var="timetable" items="${timetabling.value}" >
                                                    <c:choose>
                                                        <c:when test="${timetable.value.size() > 0}">
                                                            <c:set var="iCount" value="1"/>
                                                            <c:forEach var="i" begin="0" end="${timetable.value.size() - 1}" >
                                                                <c:choose>
                                                                    <c:when test="${timetable.value.get(i).slot == iCount}">
                                                                        <td colspan="${timetable.value.get(i).courses.credits}">
                                                                            ${timetable.value.get(i).courses.name} 
                                                                            (${timetable.value.get(i).rooms.name} : T ${timetable.value.get(i).slot} : D ${timetable.value.get(i).day})
                                                                        </td>
                                                                        <c:set var="iCount" value="${iCount + timetable.value.get(i).courses.credits}"/>
                                                                        <!-- For Type 2 -->
                                                                        <c:if test="${i == (timetable.value.size()-1)}">
                                                                            <c:if test="${iCount <= 6}">
                                                                            <c:forEach var="l" begin="${iCount}" end="6" >
                                                                                    <c:if test="${iCount <= 6}">
                                                                                        <td class="slot1 single empty"></td>
                                                                                        <c:set var="iCount" value="${iCount + 1}"/>
                                                                                    </c:if>
                                                                            </c:forEach>
                                                                            </c:if>
                                                                        </c:if>
                                                                    </c:when>
                                                                    <c:otherwise>
                                                                        <c:if test="${iCount < timetable.value.get(i).slot}">
                                                                            <c:forEach var="j" begin="${iCount}" end="${timetable.value.get(i).slot - 1}" >
                                                                                <c:if test="${iCount <= 6}">
                                                                                    <td class="slot1 single empty"></td>
                                                                                    <c:set var="iCount" value="${iCount + 1}"/>
                                                                                </c:if>
                                                                            </c:forEach>
                                                                        </c:if>
                                                                        <!-- For Type 1 -->
                                                                        <c:if test="${(iCount + timetable.value.get(i).courses.credits - 1) <= 6}">
                                                                            <td colspan="${timetable.value.get(i).courses.credits}">
                                                                                ${timetable.value.get(i).courses.name} 
                                                                                (${timetable.value.get(i).rooms.name} : T ${timetable.value.get(i).slot} : D ${timetable.value.get(i).day})
                                                                            </td>
                                                                            <c:set var="iCount" value="${iCount + timetable.value.get(i).courses.credits}"/>
                                                                        </c:if>
                                                                        <!-- For Type 3 -->    
                                                                        <c:if test="${i == (timetable.value.size()-1)}">
                                                                            <c:if test="${iCount <= 6}">
                                                                            <c:forEach var="l" begin="${iCount}" end="6" >
                                                                                    <c:if test="${iCount <= 6}">
                                                                                        <td class="slot1 single empty"></td>
                                                                                        <c:set var="iCount" value="${iCount + 1}"/>
                                                                                    </c:if>
                                                                            </c:forEach>
                                                                            </c:if>
                                                                        </c:if>    
                                                                    </c:otherwise>
                                                                </c:choose>
                                                            </c:forEach>    
                                                            
                                                        </c:when>
                                                        <c:otherwise>
                                                            <!-- Display a blank row if there no data  -->
                                                            <td colspan="6" class="slot1 single empty"></td>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </c:forEach>
                                                <!-- END Foreach by class code  -->
                                            </c:if>
                                        </c:forEach>
                                    </tr>
                                    <!-- End class -->
                                </c:forEach>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

<script type="text/javascript">
var iStatus = "${iStatus}";
if(iStatus == "ok")
{
    alert("${szMessage}");
    window.location = "${baseUrl}/cp/viewing.html"
}

</script>                                